package com.imti.mall.product.controller;

import com.imti.mall.common.Api.CommonResult;
import com.imti.mall.model.pms.pojo.PmsMemberPrice;
import com.imti.mall.product.service.PmsMemberPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/product")
public class PmsMemberPriceController {

    @Autowired
    PmsMemberPriceService pmsMemberPriceService;

    /**
     * 根据商品id查询商品会员价格
     * @param id
     * @return
     */
    @GetMapping("/getPmsMemberPriceId/{id}")
    public CommonResult getPmsMemberPriceId(@PathVariable("id") Integer id) {
        List<PmsMemberPrice> pmsMemberPriceId = pmsMemberPriceService.getPmsMemberPriceId(id);
        if(pmsMemberPriceId!=null){
            return CommonResult.success(pmsMemberPriceId);
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 根据商品会员id修改商品会员价格
     * @param pmsMemberPrice
     * @return
     */
    @RequestMapping("/upadtePmsMemberPrice")
    public CommonResult upadtePmsMemberPrice(PmsMemberPrice pmsMemberPrice) {
        Integer integer = pmsMemberPriceService.upadtePmsMemberPrice(pmsMemberPrice);
        if(integer>0){
            return CommonResult.failed("成功");
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 查询全部商品会员价格
     * @return
     */
    @RequestMapping("/findPmsMemberPrice")
    public CommonResult findPmsMemberPrice() {
        List<PmsMemberPrice> pmsMemberPrice = pmsMemberPriceService.findPmsMemberPrice();
        if(pmsMemberPrice!=null){
            return CommonResult.success(pmsMemberPrice);
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 根据商品会员id查询会员表
     * @return
     */
    @RequestMapping("/findPmsMemberPriceById/{id}")
    public CommonResult findPmsMemberPriceById(@PathVariable("id") Integer id) {
        PmsMemberPrice pmsMemberPriceById = pmsMemberPriceService.findPmsMemberPriceById(id);
        if(pmsMemberPriceById!=null){
            return CommonResult.success(pmsMemberPriceById);
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 添加会员
     * @return
     */
    @RequestMapping("/addPmsMemberPrice")
    public CommonResult addPmsMemberPrice(PmsMemberPrice pmsMemberPrice) {
        Integer integer = pmsMemberPriceService.addPmsMemberPrice(pmsMemberPrice);
        if(integer>0){
            return CommonResult.failed("成功");
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 根据商品商品会员价格id删除
     * @return
     */
    @RequestMapping("/delPmsMemberPrice/{id}")
    public CommonResult delPmsMemberPrice(@PathVariable("id") Integer id) {
        Integer integer = pmsMemberPriceService.delPmsMemberPrice(id);
        if(integer>0){
            return CommonResult.failed("成功");
        }else {
            return CommonResult.failed("失败");
        }
    }
}
